<template>
  <!-- 极简折线图 -->
   <div style="height:300px;width:100%;overflow: hidden;">
    <Row
      v-if="option.series.length==0"
      style="height:300px;background: white;"
      type="flex"
      align="middle"
      justify="center"
    >
      <img src="~@/assets/img/efficiencyAnalysis/zwsj.png" height="50%" />
    </Row>
    <div ref="main" style="overflow: hidden;height:300px;"></div>
  </div>
</template>

<script>
import { Style } from "./echartsStyle.js";
export default {
  props: {
    viewData: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      option: {
        noDataLoadingOption: {
          text: "暂无数据",
          effect: "bubble",
          effectOption: {
            effect: {
              n: 0
            }
          }
        },
        color: Style.color,
        dataZoom: [
          {
            type: "inside"
          }
        ],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985"
            }
          }
        },
        xAxis: {
          axisTick: {
            show: false
          },
          name: this.viewData != null ? this.viewData.xName : "",
          type: "category",
          // axisLabel: {
          //   interval: 0, // 0 强制显示所有，1为隔一个标签显示一个标签，2为隔两个
          //   rotate: 2 //标签旋转角度，在标签显示不下的时可通过旋转防止重叠
          // },
          // boundaryGap: false,
          data: this.viewData != null ? this.viewData.xData : []
        },
        yAxis: {
          name: this.viewData != null ? this.viewData.yName : "",
          type: "value"
        },
        series: this.viewData != null ? this.viewData.sData : [],
        animationEasing: "elasticOut",
        animationDelayUpdate: function(idx) {
          return idx * 5;
        }
      }
    };
  },
  computed: {},
  watch: {
    viewData(value) {
      if ("yName" in value) {
        this.option.yAxis.name = value.yName;
      } else {
        this.viewData.yName = "";
      }
      if ("xName" in value) {
        this.option.xAxis.name = value.xName;
      } else {
        this.viewData.xName = "";
      }
      this.option.xAxis.data = value.xData;
      this.option.series = value.sData;
      let myChart = this.$echarts.init(this.$refs.main);
      myChart.setOption(this.option, true);
    }
  },
  methods: {},
  created() {},
  mounted() {
    let myChart = this.$echarts.init(this.$refs.main);
    myChart.setOption(this.option);
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {} // 如果页面有keep-alive缓存功能，这个函数会触发
};
</script>